using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DotNetWebApi.Dtos.User;
using HotelManageSystem.Data;
using HotelManageSystem.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace HotelManageSystem.Controllers {
    [ApiController]
    [Route("api/[controller]")]
    public class AuthController : ControllerBase {
        private readonly IAuthRepository _authRepo;

        public AuthController(IAuthRepository authRepo) {
            _authRepo = authRepo;
        }

        //[HttpPost("FirstRegister")]// 用于添加一个初始账户
        //public async Task<ActionResult<ServiceResponse<int>>> FirstRegister(AddWorkerDto newWorker) {
        //    var response = await _authRepo.FirstRegister(newWorker);
        //    return Ok(response);
        //}

        /// <summary>
        /// 注册员工
        /// </summary>
        /// <param name="newWorker"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost("Register")]
        public async Task<ActionResult<ServiceResponse<string>>> Register(AddWorkerDto newWorker) {
            var response = await _authRepo.Register(newWorker);
            return Ok(response);
        }
        /// <summary>
        /// 员工登录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("Login")]
        public async Task<ActionResult<ServiceResponse<object>>> Login(OperatorLoginDto request) {
            var response = await _authRepo.Login(request.Username, request.Password);
            return Ok(response);
        }
    }
}